use std::{fmt, convert};

pub struct Sphere<T> {
    pub n: usize,
    pub center: Vec<T>,
    pub radius: T
}
impl<T: convert::From<f64> + Copy> Sphere<T> {
    pub fn new(n: usize) -> Sphere<T> {
        Sphere{n: n, center: vec![T::from(0.0); n], radius: T::from(0.0)}
    }
}
impl<T: fmt::Display> fmt::Display for Sphere<T> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut info = String::new();
        info += "球体：";
        info += format!("维度 {}；", self.n).as_str();
        info += format!("中心 (").as_str();
        for i in 0 .. self.n - 1 {
            info += format!("{}, ", self.center[i]).as_str();
        }
        info += format!("{})；", self.center[self.n - 1]).as_str();
        info += format!("半径 {}.", self.radius).as_str();
        write!(f, "{}", info)
    }
}
